fix: prefer GitHub OIDC provider if enabled #3044
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We've had reports of unusual behavior in cosign and other tools that use this idiom, when it's used in a GitHub self-hosted runner with
id-token: write
and when the environment it's hosted in also provides ambient OIDC credentials (e.g., GKE).The issue is that both GitHub's ID token is available, and the GKE environment's credentials are as well. The way this code worked before, and due to Go's map iteration randomization, this code would randomly choose between GitHub and Google credentials, producing ...confusing behavior.
This PR addresses this issue by iterating through providers in the order they were underscore-imported, rather than randomly as the map is iterated. This also changes
pkg/providers/all
* to explicitly order the imports so thatgithub
comes first, so those credentials are consistently used before any others.*This is gross.
pkg/providers/all
is gross. It's a dependency bomb, and it should not exist. I'd like to refactor this in a future set of changes to deprecateall
, and encourage consumers to explicitly import only the providers they want, then do something like sigstore/sigstore#1115 where these providers are split into separate Go modules, so consumers ofcosign
as a library don't have to import all these heavy dependencies. That's a battle for another day though.Demo that explicit import order changes the order of
init
execution: https://go.dev/play/p/TFqq6BRmLDz@haydentherapper